package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 石小俊
 * @date 2023年10月20日 15:05
 */
@WebServlet("/method")
public class MethodServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取应用名后面的地址
        // 相当于此时的url-pattern
        String servletPath = request.getServletPath();
        System.out.println("servletPath:"+servletPath);

        // 获取应用名
        String contextPath = request.getContextPath();
        System.out.println("应用名:"+contextPath);

        // 获取URI
        // 浏览器地址栏端口号后面的地址
        String uri = request.getRequestURI();
        System.out.println("uri:"+uri);

        // 获取URL
        // 浏览器地址栏完整地址
        StringBuffer url = request.getRequestURL();
        System.out.println("url:"+url);

        // 获取访问者的ip地址
        String ip = request.getRemoteAddr();
        System.out.println("访问者ip:"+ip);
    }
}
